#!/bin/bash

# 主机名初始化
read -p "please input hostname: " hostname
hostnamectl set-hostname $hostname

# IP地址初始化
read -p "ip: " ip_address

cat <<EOF > /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="none"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=$ip_address
PREFIX=24
GATEWAY=192.168.88.2
DNS1=223.6.6.6
DNS2=114.114.114.114
EOF

nmcli connection reload &> /dev/null
nmcli connection up ens33 &> /dev/null
if [ $? -eq 0 ];then
	echo "set $ip_address success!"
else
	echo "set $ip_address failure!"
	exit 66
fi
# 主机名和IP地址解析
hostname=$(hostname)
ip_address=$(hostname -I | awk '{print $1}')
echo "$ip_address   $hostname" >> /etc/hosts

# 永久关闭iptables
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld &> /dev/null
if [ $? -eq 0 ];then
	echo "firewalld is not stop "
else
	echo "firewalld is stopped"
fi
# 永久关闭SELinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

#将本地yum源换成阿里源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo &> /dev/null
#下载常用软件
yum install -y wget net-tools vim-enhanced bash-completion lftp psmise unzip bzip2 tree &> /dev/null
#时间同步
yum install -y ntpdate &> /dev/null
(crontab -l 2>/dev/null; echo "*/30 * * * *    /usr/sbin/ntpdate 120.25.115.20 &> /dev/null") | crontab -

echo "ip:
  $ip_address" > zs

#ssh端口改为44444，禁用root用户
#sed -i '/#Port/c \Port 44444' /etc/ssh/sshd_config
#sed -i '/#PermitRootLogin/c \PermitRootLogin no ' /etc/ssh/sshd_config

echo "系统初始化完成。"
